package egovframework.npqs.pqi.mobile.activity.exportquarantineresult;

import java.util.HashMap;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import egovframework.npqs.pqi.mobile.ActivityMain;
import egovframework.npqs.pqi.mobile.AppStatus;
import egovframework.npqs.pqi.mobile.BaseFragment;
import egovframework.npqs.pqi.mobile.R;
import egovframework.npqs.pqi.mobile.activity.ProdSearchActivity;
import egovframework.npqs.pqi.mobile.activity.quarantinerequest.QuarantineRequestList;
import egovframework.npqs.pqi.mobile.common.Const;
import egovframework.npqs.pqi.mobile.jsoncontent.ErrorItem;
import egovframework.npqs.pqi.mobile.jsonparser.ExportQuarantineResultListThread;
import egovframework.npqs.pqi.mobile.jsonparser.ExportQuarantineResultListThread.ExportQuarantineResultThreadCallback;
import egovframework.npqs.pqi.mobile.util.BrUtilManager;

//수출검역대기조회
public class ExportQuarantineResultList  extends BaseFragment implements OnClickListener
	, OnScrollListener
	, ExportQuarantineResultThreadCallback{
	private Context context;
	private View view;
	
	//참조클래스
	private AppStatus myapp;
	private ActivityMain am;
	private ExportQuarantineResultListThread eThread;
	private ExportQuarantineResultListAdapter eAdapter;
	
	//해더와 상단검색 부분
	private ImageButton btnLeftMenu, btnHome;
	private TextView headerTitleText, navigation;
	private EditText edit_offcd, edit_request_num;
	private ImageButton search_btn;
	//private CheckBox chk_tot_reslut;
	private TextView text_cnt;
	
	//리스트부분
	private ListView listView;
	
	//하단부분
	private Button footer01Btn, footer02Btn, footer03Btn, footer04Btn;
	
	//검색버튼을 누르면 나타나는 영역
	private ImageButton btn_oneday, btn_threeday, btn_sevenday;
	private EditText edit_edate, edit_sdate;
	private ImageButton btn_e_calender, btn_s_calender;
	private RadioButton chk_user, chk_all_user;
	private EditText edit_place, edit_in_out;
	private EditText edit_detail_offcd, edit_detail_request_no;
	private ImageButton search_detail_btn;
	
	//검색버튼을 누르면 나타나는 영역
	private LinearLayout hdLinearLayout;
	//검색버튼을 누르면 아래부분이 검정으로 변하는 영역
	private LinearLayout black_layout;
	//체크하면 체크한 항목을 넣어두는 Array
	//private ArrayList<Integer> selectedArr;
	//상세 검색인지 구분하는 값
	private boolean searchState;
	//페이징을 구분하는 값
	private boolean pageState;
	//현제 페이지 수
	private int mPageCnt = 1;
	//리스트 카운트 수
	private int nTotCnt = 0;
	//상수
	private final static int MSG_QUARANTINE_COMPLETED = 0;
	private final static int MSG_QUARANTINE_ERROR = 1;
	private final static int MSG_NETWORK_ERROR = 2;
	
	//기타
	private Intent intent;
	private String checkStr;
	private Paint paint;
	
	//호출 결과값
	private String mResult;
	
	/* G-MOBILE 변수*/
    private String temp;
    
    HashMap<String,String>	searchMap;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		AppStatus.navigation.addPathLocation("수출검역대기조회");
		searchMap = new HashMap<String,String>();
		if(view != null){
			ViewGroup parent = (ViewGroup)view.getParent();
			if(parent !=null)
				parent.removeView(view);
		}else{
			view = inflater.inflate(R.layout.fragment_list, container, false);
			init();
		}
		return view;
	}
	
	private void init(){
		context = view.getContext();
		myapp = (AppStatus) context.getApplicationContext();
		myapp.startBroker(context);
		am = (ActivityMain) ActivityMain.am;
		//해더와 상단검색부분
		btnLeftMenu = (ImageButton)view.findViewById(R.id.btnLeftMenu);
		btnHome = (ImageButton)view.findViewById(R.id.btnHome);
		/*btnLogin = (ImageButton)view.findViewById(R.id.btnLogin);*/
		headerTitleText = (TextView)view.findViewById(R.id.headerTitleText);
		edit_offcd = (EditText)view.findViewById(R.id.edit_offcd);
		edit_request_num = (EditText)view.findViewById(R.id.edit_request_num);
		search_btn = (ImageButton)view.findViewById(R.id.search_btn);
		//chk_tot_reslut = (CheckBox)view.findViewById(R.id.chk_tot_reslut);
		text_cnt = (TextView)view.findViewById(R.id.text_cnt);
		//리스트부분
		listView = (ListView)view.findViewById(R.id.quarantine_list);
		//하단부분
		footer01Btn = (Button)view.findViewById(R.id.footer01Btn);
		footer02Btn = (Button)view.findViewById(R.id.footer02Btn);
		footer03Btn = (Button)view.findViewById(R.id.footer03Btn);
		footer04Btn = (Button)view.findViewById(R.id.footer04Btn);
		//검색버튼을 누르면 나타나는 영역
		btn_oneday = (ImageButton)view.findViewById(R.id.btn_oneday);
		btn_threeday = (ImageButton)view.findViewById(R.id.btn_threeday);
		btn_sevenday = (ImageButton)view.findViewById(R.id.btn_sevenday);
		edit_sdate = (EditText)view.findViewById(R.id.edit_sdate);
		edit_edate = (EditText)view.findViewById(R.id.edit_edate);
		btn_s_calender = (ImageButton)view.findViewById(R.id.btn_s_calender);
		btn_e_calender = (ImageButton)view.findViewById(R.id.btn_e_calender);
		chk_user =(RadioButton)view.findViewById(R.id.chk_user);
		chk_all_user =(RadioButton)view.findViewById(R.id.chk_all_user);
		edit_place = (EditText)view.findViewById(R.id.edit_place);	// 검역장소 에디트 박스
		edit_in_out = (EditText)view.findViewById(R.id.edit_in_out);	// 수출입업체 에디트 박스
		edit_detail_offcd = (EditText)view.findViewById(R.id.edit_detail_offcd);
		edit_detail_request_no = (EditText)view.findViewById(R.id.edit_detail_request_no);
		search_detail_btn = (ImageButton)view.findViewById(R.id.search_detail_btn);
		//검색버튼을 누르면 나타나는 영역
		hdLinearLayout =(LinearLayout)view.findViewById(R.id.search_hd_layout);
		//검색버튼을 누르면 아래부분이 검정으로 변하는 영역
		black_layout = (LinearLayout)view.findViewById(R.id.black_layout);
		//체크하면 체크한 항목을 넣어두는 Array
		//selectedArr = new ArrayList<Integer>();
		//상세 검색인지 구분하는 값
		searchState = true;
		
		//리스너 부착
		btnLeftMenu.setOnClickListener(this);
		btnHome.setOnClickListener(this);
		/*btnLogin.setOnClickListener(this);*/
		search_btn.setOnClickListener(this);
		footer01Btn.setOnClickListener(this);
		footer02Btn.setOnClickListener(this);
		footer03Btn.setOnClickListener(this);
		footer04Btn.setOnClickListener(this);
		btn_oneday.setOnClickListener(this);
		btn_threeday.setOnClickListener(this);
		btn_sevenday.setOnClickListener(this);
		btn_s_calender.setOnClickListener(this);
		btn_e_calender.setOnClickListener(this);
		search_detail_btn.setOnClickListener(this);
		
		listView.setOnScrollListener(this);
		
		//타이틀 부착
		headerTitleText.setText("수출검역대기조회");
		
		navigation = (TextView)view.findViewById(R.id.navigation);
		navigation.setText(AppStatus.navigation.getPath());
		Log.i("AppStatus.navigation.getPath()->", AppStatus.navigation.getPath());
		
		//체크박스올
		/*chk_tot_reslut.setVisibility(View.VISIBLE);
		chk_tot_reslut.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if(isChecked){
					selectedArr.removeAll(selectedArr);
					for (int i = 0; i < myapp.getArrQuarantineResultItem().size(); i++) {
						selectedArr.add(i);
					}
				}else{
					selectedArr.removeAll(selectedArr);
				}
				eAdapter.notifyDataSetChanged();
			}
		});*/
		
		//셋팅
		chk_user.setText(myapp.getLoginItem().getUserNm());//검색버튼눌렀을때 로그인이름
		chk_all_user.setChecked(true);//기본값은 전체로
		edit_sdate.setText(BrUtilManager.getCurrentDateTime(0));//달력에디트는 현제날짜로 초기화
		edit_edate.setText(BrUtilManager.getCurrentDateTime(0));//달력에디트는 현제날짜로 초기화
		edit_sdate.setInputType(InputType.TYPE_NULL);
		edit_edate.setInputType(InputType.TYPE_NULL);
		edit_offcd.setText(myapp.getLoginItem().getOffCd());//오프시디 초기화
		edit_detail_offcd.setText(myapp.getLoginItem().getOffCd());//상세오프시디 초기화
		footer03Btn.setBackgroundResource(R.drawable.f_blank_sel);//하단버튼 초기화
		footer04Btn.setBackgroundResource(R.drawable.foot_quarantine_selector);//하단버튼 초기화
		
		//초기화
		eAdapter = new ExportQuarantineResultListAdapter();
		
		//black_layout 검정으로 칠하기
		paint = new Paint();
		paint.setColor(Color.BLACK);
		paint.setAlpha(70);
		black_layout.setBackgroundColor(paint.getColor());
		
		if(!myapp.isDataLoadState()){
			firstDataLoad();
		}
	}
	
	private void firstDataLoad(){
		myapp.startBroker(context);
		myapp.showDialogNo(context);	// 페이지가 로드 될때 다이얼로그 출력.
		temp = "처음검색";
		//asyncTaskIsConnectedVPN();
		threadStart();
	}
	
	//조회버튼 : 신청번호로 조회, 상세조회 아님
	private void searchList(){
		myapp.showDialogNo(context);
		
		searchMap.put(Const.SEARCHOFFCD, edit_offcd.getText().toString());
		searchMap.put(Const.SEARCHSDATE, edit_sdate.getText().toString());
		searchMap.put(Const.SEARCHEDATE, edit_edate.getText().toString());
		searchMap.put(Const.TARGETPAGE, ""+mPageCnt);
		
		if(searchState){
			if(edit_offcd.getText().toString().equals("")){	// offcd가 비어있을 경우
				myapp.utilm.ShowDialog(context, "오류", "검역신청번호를 입력해 주세요.", 20);
				return;
			}
			
			searchMap.put(Const.SEARCHRECNO, edit_request_num.getText().toString());
			searchMap.put(Const.SEARCHUSERSN, "");
			searchMap.put(Const.SEARCHINSPLACE, "");
			searchMap.put(Const.SEARCHVENNM, "");
		}else{
			searchMap.put(Const.SEARCHRECNO, edit_detail_request_no.getText().toString());
			
			if(chk_user.isChecked()){
				searchMap.put(Const.SEARCHUSERSN, myapp.getLoginItem().getUserSn());
			}else{
				searchMap.put(Const.SEARCHUSERSN, "");			
			}

			searchMap.put(Const.SEARCHINSPLACE, edit_place.getText().toString());
			searchMap.put(Const.SEARCHVENNM, edit_in_out.getText().toString());
		}
		
		Log.i("검색 상태 값","현재 상태값 = " + searchState);
		Log.i("페이지 상태 값","현재 상태값 = " + pageState);
		
		temp = "조건검색";
		threadStart();
		searchClear();
	}
	
	public void threadStart(){
		if("조건검색".equals(temp)){
    		eThread = new ExportQuarantineResultListThread(context, this, searchMap, pageState, AppStatus.getmUserId());
    		eThread.start();
    	}
    	if("처음검색".equals(temp)){
    		System.out.println("들어옴2");
    		eThread = new ExportQuarantineResultListThread(context, this, myapp.getLoginItem().getOffCd(), AppStatus.getmUserId());
    		eThread.start();
    	}
	}
	
	@Override
	public void onResume() {
		if(myapp.isFinishState()){
			((Activity) context).finish();
			myapp.setFinishState(false);
		}
		if(myapp.isDataLoadState()){
			myapp.startBroker(context);
			myapp.setDataLoadState(false);
			firstDataLoad();
		}
		if(myapp.isAbleHome()){
			btnHome.performClick();
			myapp.setAbleHome(false);
		}
		super.onResume();
	}
	
	//OnScrollListener : 페이지가 바뀌면....
	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		if (scrollState == SCROLL_STATE_IDLE) 
		{
			if(!pageState){
				if (listView.getLastVisiblePosition() >= listView.getCount()-1) 
				{
					if(nTotCnt - listView.getCount() > 0){
						pageState = true;
						mPageCnt ++;
						searchList();
						//myapp.utilm.showToast(context, "다음페이지로  = " + listView.getCount());					
					}else{
						myapp.utilm.showToast(context, "다음페이지 없음 ");
					}
				}				
			}
		}
	}

	//OnScrollListener
	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
		
	}

	//OnScrollListener : 백버튼
	@Override
	public void Onback() {
		if(myapp.isQuarantineState()){
		}else{
			layoutHidden(true);
			footer01Btn.setBackgroundResource(R.drawable.f_search_sel);
			myapp.setQuarantineState(false);
			searchState = true;
		}
	}
	
	//Fragmant
	@Override
	public void onPause() {
		layoutHidden(true);
		myapp.setQuarantineState(true);
		myapp.setFinishState(false);
		super.onPause();
	}
	
	//ExportQuarantineResultThreadCallback
	@Override
	public void OnExportQuarantineResultCompleted(boolean isNetworkConntected,
			boolean results, String message) {
		System.out.println("들어옴3");
		if(myapp.dialog != null && myapp.dialog.isShowing()) {
			myapp.dialog.dismiss();
		}
		
		Log.i("message-->", "message-->"+message);
		if(null != message && !"".equals(message)){
			mResult = message;
			reesultToast();
		}
		
		if(!isNetworkConntected){	// 네트워크 접속이 되어 있지 않을 때
			Message msg = handler.obtainMessage();
			msg.what = MSG_NETWORK_ERROR;
			handler.sendMessage(msg);
			return;
		}
		if(results) {
			Message msg = handler.obtainMessage();
			msg.what = MSG_QUARANTINE_COMPLETED;
			handler.sendMessage(msg);
		}
	}
	//ExportQuarantineResultThreadCallback
	@Override
	public void OnExportQuarantineResultError(ErrorItem errorItem) {
		Log.i("dialog2-->", "dialog2-->");
		if(myapp.dialog !=null && myapp.dialog.isShowing()) {
			myapp.dialog.dismiss();
		}

		Message msg = handler.obtainMessage();
		msg.what = MSG_QUARANTINE_ERROR;
		if(errorItem != null) {
			msg.obj = errorItem.getrDesc();
		}
		handler.sendMessage(msg);
	}
	
	private Handler handler = new Handler() {
		@Override
		public void handleMessage(final Message msg) {
			switch (msg.what) {
			case MSG_QUARANTINE_COMPLETED:
				layoutHidden(true);	// 일반 검색 or 상세 검색 으로 검색 했을 때 상세 검색 창은 닫는다.
				if(myapp.getArrExportListItem().get(0).getTotalRows()==null){
					nTotCnt = 0;
				}else{
					nTotCnt = Integer.parseInt(myapp.getArrExportListItem().get(0).getTotalRows());
				}
				text_cnt.setText("총 "+nTotCnt+"건이 조회되었습니다.");
				eAdapter.notifyDataSetChanged();
				listView.setAdapter(eAdapter);	
				if(pageState) listView.setSelection(listView.getCount()- 17);
				pageState = false;
				break;

			case MSG_QUARANTINE_ERROR:
				String errMsg = "";
				if(msg == null ||msg.obj.toString().equals("")){
					errMsg = "서버와의 연결에 실패하였습니다.";
				}else{
					errMsg = msg.obj.toString();	
				}
				layoutHidden(true);	// 일반 검색 or 상세 검색 으로 검색 했을 때 상세 검색 창은 닫는다.
				
				text_cnt.setText("데이터가 존재하지 않습니다.");
				eAdapter.notifyDataSetChanged();
				listView.setAdapter(eAdapter);
				if(!pageState){
					myapp.utilm.ShowDialog(context, "실패", errMsg, 20);
				}
				
				pageState = false;
				break;

			case MSG_NETWORK_ERROR:
				myapp.utilm.ShowDialog(context, "실패", "네트워크에러", 20);

			default:
				break;
			}
		}
	};

	//OnClickListener
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnLeftMenu: //메뉴버튼 : 누르면 리스트가 슬라이딩된다.
			am.toggle();
			break;
			
		case R.id.btnHome://홈버튼 : 누르면 홈으로간다
			getActivity().onBackPressed();
			break;
			
		/*case R.id.btnLogin://종료버튼 : 어플리케이션을 종료한다.
			myapp.appFinish(context);
			break;*/
			
		case R.id.search_btn://조회버튼 : 검역신청번호로 조회한다.
			myapp.utilm.InputKeybordHidden(context, edit_request_num);
			searchState = true;
			pageState = false;
			mPageCnt =1;
			searchList();
			break;
			
		case R.id.footer01Btn://하단상세검색버튼
			if(hdLinearLayout.getVisibility() == View.VISIBLE){
				myapp.setQuarantineState(true);
				searchState = true;
			}else if(hdLinearLayout.getVisibility() == View.GONE){
				myapp.setQuarantineState(false);
				searchState = false;
			}
			layoutHidden(searchState);
			break;

		case R.id.footer02Btn://품목결과 버튼: 품목결과창이 뜬다.
			intent = new Intent(getActivity().getApplication(), ProdSearchActivity.class);
			startActivity(intent);
			break;
			
		case R.id.footer03Btn://전결버튼
			//approve();
			break;
			
		case R.id.footer04Btn://소독대기조회 : 화면이동
			QuarantineRequestList quarantineRequest = new QuarantineRequestList();
			addFragmentReplace(R.id.base_frame, quarantineRequest, QuarantineRequestList.class.getName());			
			break;
			
		case R.id.btn_oneday://1일전버튼
			btn_oneday.setBackgroundResource(R.drawable.btn_oneday_on);
			btn_threeday.setBackgroundResource(R.drawable.btn_threeday_off);
			btn_sevenday.setBackgroundResource(R.drawable.btn_sevenday_off);
			edit_sdate.setText(BrUtilManager.getCurrentDateTime(1));
			edit_edate.setText(BrUtilManager.getCurrentDateTime(0));
			break;
			
		case R.id.btn_threeday://3일전버튼
			btn_oneday.setBackgroundResource(R.drawable.btn_oneday_off);
			btn_threeday.setBackgroundResource(R.drawable.btn_threeday_on);
			btn_sevenday.setBackgroundResource(R.drawable.btn_sevenday_off);
			edit_sdate.setText(BrUtilManager.getCurrentDateTime(3));
			edit_edate.setText(BrUtilManager.getCurrentDateTime(0));		
			break;
			
		case R.id.btn_sevenday://7일전버튼
			btn_oneday.setBackgroundResource(R.drawable.btn_oneday_off);
			btn_threeday.setBackgroundResource(R.drawable.btn_threeday_off);
			btn_sevenday.setBackgroundResource(R.drawable.btn_sevenday_on);
			edit_sdate.setText(BrUtilManager.getCurrentDateTime(7));
			edit_edate.setText(BrUtilManager.getCurrentDateTime(0));	
			break;
			
		case R.id.btn_s_calender://1번째달력버튼
			sDateSetting();
			break;
			
		case R.id.btn_e_calender://2번째달력버튼
			eDateSetting();
			break;
			
		case R.id.search_detail_btn://상세조회버튼
			myapp.utilm.InputKeybordHidden(context, edit_place);
			myapp.utilm.InputKeybordHidden(context, edit_in_out);
			myapp.utilm.InputKeybordHidden(context, edit_detail_request_no);
			searchState = false;
			pageState = false;
			mPageCnt =1;
			searchList();
			break;
		}
	}
	
	//하단상세검색버튼
	private void layoutHidden(boolean state){
		if(state){//검색 모드가 아닐 때
			hdLinearLayout.setVisibility(View.GONE);
			black_layout.setVisibility(View.GONE);
			footer01Btn.setBackgroundResource(R.drawable.f_search_sel);
		
		}else{//상세 검색 일 때
			hdLinearLayout.setVisibility(View.VISIBLE);
			black_layout.setVisibility(View.VISIBLE);
			footer01Btn.setBackgroundResource(R.drawable.f_search);
		}
	}
	//일괄결재
	/*private void approve(){
		checkStr ="";
		if(selectedArr.size() == 0){
			myapp.utilm.ShowDialog(context, "오류", "항목을 하나라도 선택해 주세요.", 20);
		}else{
			for (int i = 0; i < selectedArr.size(); i++) {
				if(checkStr.equals("")){
					checkStr = myapp.getArrExportListItem().get(selectedArr.get(i)).getOffCd() +"-"+myapp.getArrExportListItem().get(selectedArr.get(i)).getRecNo();
				}else{
					checkStr += ","+myapp.getArrExportListItem().get(selectedArr.get(i)).getOffCd()+"-"+myapp.getArrExportListItem().get(selectedArr.get(i)).getRecNo();
				}
			}
			intent = new Intent(getActivity().getApplication(), EnblocResultInsertActivity.class);
			intent.putExtra("checkStr", checkStr);
			startActivity(intent);
		}
	}*/
	//1번째달력버튼
	private void sDateSetting(){
		String str = edit_sdate.getText().toString();
		int sYear, sDay, sMonth;
		sYear = Integer.parseInt(str.substring(0, 4));
		sMonth = Integer.parseInt(str.substring(5, 7)) -1;
		sDay = Integer.parseInt(str.substring(8, 10));
		DatePickerDialog dpd = new DatePickerDialog(context,
		        new DatePickerDialog.OnDateSetListener() {
		            @Override
		            public void onDateSet(DatePicker view, int year,
		                    int monthOfYear, int dayOfMonth) {
		            	String months = "";
		            	String days = "";
		            	if(String.valueOf(monthOfYear + 1).length() == 1){
		            		months ="0"+(monthOfYear+1);
		            	}else{
		            		months = String.valueOf((monthOfYear+1));
		            	}
		            	if(String.valueOf(dayOfMonth).length() == 1){
		            		days ="0"+dayOfMonth;
		            	}else{
		            		days =String.valueOf(dayOfMonth);		            		
		            	}
		            	edit_sdate.setText(year + "-"
		                        + months + "-" + days);
		            }
		        }, sYear, sMonth, sDay);
		dpd.show();
	}
	//2번째달력버튼
	private void eDateSetting(){
		String str = edit_edate.getText().toString();
		int eYear, eDay, eMonth;
		eYear = Integer.parseInt(str.substring(0, 4));
		eMonth = Integer.parseInt(str.substring(5, 7)) -1;
		eDay = Integer.parseInt(str.substring(8, 10));
		DatePickerDialog dpd = new DatePickerDialog(context,
		        new DatePickerDialog.OnDateSetListener() {
		            @Override
		            public void onDateSet(DatePicker view, int year,
		                    int monthOfYear, int dayOfMonth) {
		            	String months = "";
		            	String days = "";
		            	if(String.valueOf(monthOfYear + 1).length() == 1){
		            		months ="0"+(monthOfYear+1);
		            	}else{
		            		months = String.valueOf((monthOfYear+1));
		            	}
		            	if(String.valueOf(dayOfMonth).length() == 1){
		            		days ="0"+dayOfMonth;
		            	}else{
		            		days =String.valueOf(dayOfMonth);		            		
		            	}
		            	edit_edate.setText(year + "-"
		                        + months + "-" + days);
		            }
		        }, eYear, eMonth, eDay);
		dpd.show();
	}
	
	//검색후 초기화
	private void searchClear(){
		if(searchState){
			edit_sdate.setText(BrUtilManager.getCurrentDateTime(0));
			edit_edate.setText(BrUtilManager.getCurrentDateTime(0));
			chk_user.setChecked(false);
			chk_all_user.setChecked(true);
			edit_place.setText("");
			edit_in_out.setText("");
			edit_detail_request_no.setText("");
			btn_oneday.setBackgroundResource(R.drawable.btn_oneday_off);
			btn_threeday.setBackgroundResource(R.drawable.btn_threeday_off);
			btn_sevenday.setBackgroundResource(R.drawable.btn_sevenday_off);
		}else{
			edit_request_num.setText("");
		}
	}
	
	class ExportQuarantineResultListAdapter extends BaseAdapter {
		TextView txt_request_no, txt_request_date;
		TextView txt_ven_name, txt_nat_name;
		TextView txt_prod_name, txt_ins_place;
		LinearLayout linear_chk_layout;
		CheckBox chk_result_list;

		@Override
		public int getCount() {
			return myapp.getArrExportListItem().size();
		}

		@Override
		public Object getItem(int position) {
			return myapp.getArrExportListItem().get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			if (convertView == null || convertView != null) {
    			LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    			convertView = inflater.inflate(R.layout.list_chk_item, parent, false);
    		}
			
			linear_chk_layout = (LinearLayout)convertView.findViewById(R.id.linear_chk_layout);
			chk_result_list = (CheckBox)convertView.findViewById(R.id.chk_result_list);
			chk_result_list.setVisibility(View.GONE);
			txt_request_no = (TextView)convertView.findViewById(R.id.txt_request_no);
			txt_request_date = (TextView)convertView.findViewById(R.id.txt_request_date);
			txt_ven_name = (TextView)convertView.findViewById(R.id.txt_ven_name);
			txt_nat_name = (TextView)convertView.findViewById(R.id.txt_nat_name);
			txt_prod_name = (TextView)convertView.findViewById(R.id.txt_prod_name);
			txt_ins_place = (TextView)convertView.findViewById(R.id.txt_ins_place);
			
			txt_request_no.setText(myapp.getArrExportListItem().get(position).getOffCd() + "-" +myapp.getArrExportListItem().get(position).getRecNo());
			txt_request_date.setText(myapp.getArrExportListItem().get(position).getFieDe());
			txt_ven_name.setText(myapp.getArrExportListItem().get(position).getVenNm());
			txt_nat_name.setText(myapp.getArrExportListItem().get(position).getDelayNm());
			txt_prod_name.setText(myapp.getArrExportListItem().get(position).getPrdlstNm());
			txt_ins_place.setText(myapp.getArrExportListItem().get(position).getMetNm());
			
			if(myapp.getArrExportListItem().get(position).getDelayAt().equals("Y")){
				txt_nat_name.setTextColor(Color.RED);
			}
			
			/*if(selectedArr.contains(position)){
				chk_result_list.setChecked(true);
			}else{
				chk_result_list.setChecked(false);
			}
			
			chk_result_list.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
					if(isChecked){
						selectedArr.add(position);	
						
					}else{
						if(selectedArr.contains(position)){                                               
							selectedArr.remove(selectedArr.indexOf(position));                                   
                        }
					}
				}
			});*/
			
			convertView.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					listItemClickEvent(position);
				}
			});
			
			return convertView;
		}
		
		private void listItemClickEvent(final int position) {
			intent = new Intent(getActivity().getApplication(), ExportQuarantineResultDetail.class);
			intent.putExtra("recNo", myapp.getArrExportListItem().get(position).getRecNo());
			startActivity(intent);
		}
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		AppStatus.navigation.delPathLocation();
	}
	
	private void reesultToast() {
		am.runOnUiThread(new Runnable() {

            public void run() {
                Toast toast = Toast.makeText(context, mResult, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 50);
                toast.show();
            }
        });
    }
	
}
